package com.ld.security.common.core.util;

import cn.hutool.core.util.HashUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.crypto.SecureUtil;
import com.ld.security.common.core.anno.IdKey;
import com.ld.security.common.core.base.po.SuperPo;

public class UuidUtil {


    public static Object initIdKey(Object obj){


        ReflectionUtil.applyAllDeclaredFields(obj,IdKey.class,(anno,name,val) -> {
            StringBuffer sb =   new StringBuffer();
            for (String s : anno.value()) {
                Object v = ReflectionUtil.invokeGetter(obj,s);
                if(v == null){
                    //一个值为空 都不映射
                    return;
                }
                sb.append(v);
            }
            String id = getId(sb.toString());
            ReflectionUtil.invokeSetter(obj,name,id);
        });

        return obj;
    }


    public static String getId(String id){
        return HashUtil.murmur64(id.getBytes())+"";
    }

    public static String getId(){
        return IdUtil.objectId();
    }

    public static String md5(String key){
        return SecureUtil.md5(key);
    }


}
